package com.dsl.dslsuzhou.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 摄像头接口配置
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "camera")
public class CameraConfig {
    
    /**
     * 第三方接口配置
     */
    private ThirdParty thirdParty = new ThirdParty();
    
    /**
     * 计数接口配置
     */
    private Count count = new Count();
    
    /**
     * 限流配置
     */
    private RateLimit rateLimit = new RateLimit();
    
    /**
     * 熔断配置
     */
    private CircuitBreaker circuitBreaker = new CircuitBreaker();
    
    /**
     * 重试配置
     */
    private Retry retry = new Retry();
    
    /**
     * 参数校验配置
     */
    private Validation validation = new Validation();
    
    @Data
    public static class ThirdParty {
        /**
         * 第三方接口基础URL
         */
        private String baseUrl = "http://192.168.127.8:38080";
        
        /**
         * 摄像头分页接口路径
         */
        private String cameraPagePath = "/api/uni/video/camera/page";

        /**
         * HTTP请求方法
         */
        private String httpMethod = "GET";

        /**
         * 连接超时时间（秒）
         */
        private int connectTimeout = 2;
        
        /**
         * 响应超时时间（秒）
         */
        private int responseTimeout = 5;
    }
    
    @Data
    public static class Count {
        /**
         * 批次大小
         */
        private int batchSize = 150;
    }
    
    @Data
    public static class RateLimit {
        /**
         * 全局QPS限制
         */
        private int qps = 200;
        
        /**
         * 限流时间窗口（秒）
         */
        private int timeWindow = 1;
    }
    
    @Data
    public static class CircuitBreaker {
        /**
         * 连续失败阈值
         */
        private int failureThreshold = 5;
        
        /**
         * 熔断窗口时间（秒）
         */
        private int waitDurationInOpenState = 60;
        
        /**
         * 半开状态下的测试请求数
         */
        private int permittedNumberOfCallsInHalfOpenState = 3;
        
        /**
         * 滑动窗口大小
         */
        private int slidingWindowSize = 10;
    }
    
    @Data
    public static class Retry {
        /**
         * 最大重试次数
         */
        private int maxAttempts = 3;
        
        /**
         * 初始重试间隔（毫秒）
         */
        private long initialInterval = 500;
        
        /**
         * 重试间隔倍数
         */
        private double multiplier = 2.0;
    }
    
    @Data
    public static class Validation {
        /**
         * devIds最大数量限制
         */
        private int maxDevIds = 2000;
        
        /**
         * 默认页码
         */
        private int defaultCurrent = 1;
        
        /**
         * 默认页大小
         */
        private int defaultSize = 10;
        
        /**
         * 最大页大小
         */
        private int maxSize = 200;
    }
}
